﻿using Logistics.EntityFrameworkCore;
using Logistics.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Logistics.Car
{
    public class FieIdRepository : IFieIdRepository
    {
        private readonly LogisticsDbContext db;

        public FieIdRepository(LogisticsDbContext _db)
        {
            db = _db;
        }
        /// <summary>
        /// 外协添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public async Task<int> Create(Field m)
        {
            db.Field.Add(m);
            return db.SaveChanges();
        }

        public async Task<int> Delete(int Id)
        {
            var list = db.Field.Find(Id);
            db.Field.Remove(list);

            return db.SaveChanges();
        }
        /// <summary>
        /// 基础车辆反填
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Field> GetCarryById(int Id)
        {
            var list = db.Field.Find(Id);
            return list;
        }
        /// <summary>
        /// 基础车辆修改
        /// </summary>
        /// <param name="ca"></param>
        /// <returns></returns>
        public async Task<int> UpdateVehicle(Field ca)
        {
            var list = await db.Field.FindAsync(ca.Id);
            list = ca;
            db.Entry(list).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return db.SaveChanges();
        }
        /// <summary>
        /// 显示外协
        /// </summary>
        /// <returns></returns>
        public async Task<List<Field>> GetVehicle()
        {
            var list=db.Field.ToList();
            return list;
        }
    }
}
